// game_over_dig.js
var Gcommon = require('./../../model/Common');
cc.Class({
  extends: cc.Component,
  properties: {
    mask: {
      type: cc.Node,
      default: null
    },

    mask_opacity: 128,

    content: {
      type: cc.Node,
      default: null
    },

    score: {
      type: cc.Label,
      default: null
    },

    money: {
      type: cc.Label,
      default: null
    },

    callBack: null
  },

  // use this for initialization
  onLoad: function() {},

  show_dlg: function(cb) {
    //接收一个隐藏弹窗的回调函数
    this.callBack = cb;

    //分数金钱赋值
    this.score.string = this.callBack.score;
    let moneyValue = Math.round(this.callBack.score / 10);
    this.money.string = '+' + moneyValue;
    Gcommon.money += moneyValue;
    Gcommon.setUserDate({ data: Gcommon.money, type: 'updateMoney' });

    this.node.active = true;
    // mask 渐变出来;
    this.mask.opacity = 0;
    var fin = cc.fadeTo(0.3, this.mask_opacity);
    this.mask.runAction(fin);

    // dlg由小到大
    this.content.scale = 0;
    // var s = cc.scaleTo(0.4, 1).easing(cc.easeBackOut());
    // this.content.runAction(s);
    var sca = cc.scaleTo(0.3, 1).easing(cc.easeIn(0.1));
    this.content.runAction(sca);
  },

  hide_dlg: function() {
    var fout = cc.fadeOut(0.3);
    this.mask.runAction(fout);

    var s = cc.scaleTo(0.3, 0).easing(cc.easeBackIn());
    var end_func = cc.callFunc(
      function() {
        this.node.active = false;
        this.node.destroy();
      }.bind(this)
    );
    var seq = cc.sequence([s, end_func]);
    this.content.runAction(seq);
  },

  //分享好友
  onShare() {
    console.log('游戏内分享好友');
    Gcommon.share();
  },

  // 回到首页
  returnHome() {
    this.hide_dlg();
    cc.director.loadScene('home');
    // console.log(this.callBack);
    // this.callBack.goHome();
    // setTimeout(() => {
    //   // this.callBack.goHome()
    // }, 400);
  },

  // 重新开始游戏
  reStart() {
    console.log('重新开始游戏');
    this.callBack.restart();
    this.hide_dlg();
  }
});
